$(document).ready(init);
function init() {
	 if($('#dg') != null)
	 {	    		 
	     $('#dg').datagrid({             
             onLoadSuccess: function(data) {
             	if(data.success != 0)
             	{
             		showErrMsg(data);
             	}
             }
         });
	 }
}

function showErrMsg(data)
{	
	if(data.success==1)
	{
		window.parent.location.href="./admin/login";
	}
	else
	{
		$.messager.alert("错误",data.msg,"error");
	}
	
}

//winId:窗体ID号，唯一值,title：窗体标题,width：窗体宽度,height：窗体高度,showUrl：窗体显示的页面,
//winId,title,width,height,showUrl,okUrl,refresh_fun
function open_fun(params)
{
    var win = new top.Ext.Window({
        id:params.winId,
        title: params.title,  
        height: params.height,
        width : params.width,
        modal:true,
        bodyStyle:"bgcolor:white",
        items:[{
            contentEl : Ext.DomHelper.append(document.body, {
                tag : 'iframe',
                id:'myIframe',
                name:'myIframe',
                style : "border 0px none;scrollbar:true;",
                height : "100%",
                width : "100%"
            })
        }],
        buttons:[{
            text:' 保 存 ',
            handler:function(){
                //调用子窗体的保存函数，得到返回值true或false
                var ret = parent.document.getElementById('myIframe').contentWindow.btnSave_click();
                if(ret)
                {
                    parent.Ext.getCmp(params.winId).close();
                    var callback_fun = params.refresh_fun;
                    if(typeof(callback_fun) == 'function')
                    {
                        callback_fun();
                    }
                    win = null;
                }
            }
        },{
            text:' 取 消 ',
            handler:function(){
                saveFlag = false;
                parent.Ext.getCmp(params.winId).close();
                win == null;
            }
        }],
        listeners:{
            "show":function(){
                var showUrl = params.showUrl;
                if(showUrl.indexOf('?')>0)
                {
                    showUrl = showUrl + '&rnd='+Math.random();
                }
                else
                {
                    showUrl = showUrl + '?rnd='+Math.random();
                }
                parent.document.getElementById("myIframe").src= showUrl;
            }}
      });
    
    win.show();
}
